package com.shiwaixiangcun.monitor;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017/6/26.
 */
@Component
public class ApplicationContextStartedListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //root application context 没有parent，他就是老大.
        ApplicationContext applicationContext = event.getApplicationContext();
        if (applicationContext.getParent() == null) {
            //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
           // CanalDataSynchronizer synchronizer = applicationContext.getBean(CanalDataSynchronizer.class);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    //synchronizer.startSync();
                }
            }).start();

        }
    }
}